﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using PNProject.EF;
using PNProject.Core;

namespace PNProject.Core.Converter
{
    public class BannerConverter
    {
        public static Banner ToBanner(BannerModel ban)
        {
            try
            {
                Banner obj = new Banner();
                obj.URL = ban.URL;
                obj.URLEN = ban.URLEN;
                obj.Description = ban.Description;
                obj.DescriptionEN = ban.DescriptionEN;
                obj.Lang = true;
                obj.Arrang = 0;
                obj.Type = 0;
                return obj;            
            }
            catch(Exception e)
            {
                return new Banner() {BannerID=-1};
            }
        }

        public static BannerModel BannerTo(Banner ban)
        {
            BannerModel obj = new BannerModel();
            obj.BannerID = ban.BannerID.ToString();
            obj.URL = ban.URL;
            obj.URLEN = ban.URLEN;
            obj.Description = ban.Description;
            obj.DescriptionEN = ban.DescriptionEN;
            obj.Lang = ban.Lang.HasValue? ban.Lang.ToString(): "True";
            obj.Arrang = ban.Arrang.HasValue ? ban.Arrang.ToString() : "0";
            obj.Type = ban.Type.HasValue ? ban.Type.ToString() : "0";
            return obj;            
        }
    }
}